package demo1.servlet.userManager;

import com.alibaba.fastjson.JSON;
import demo1.pojo.users;
import demo1.service.userService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/cancelAccount")
public class cancelAccount extends HttpServlet {//封号
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //接受数据
        BufferedReader br = req.getReader();
        String params = br.readLine();//json字符串

        //转为user对象
        users users = JSON.parseObject(params, users.class);
        //调用service验证
        userService check = new userService();
        try {
            int num = check.cancelAccount(users);
            if (num == 1) {
                //写入成功
                resp.getWriter().write("success");
            }
            else if (num == 0) {
                //已经是封号状态了
                resp.getWriter().write("error");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
